from rest_framework.generics import ListAPIView, GenericAPIView
from rest_framework.mixins import RetrieveModelMixin
from rest_framework.response import Response
from rest_framework.views import APIView

from apps.goods.models import GoodsCategory, SKU
from apps.goods.serializers.goods import GoodsCategorySerializer, GoodsSKUSerializer


class GoodsCategoryAPIView(ListAPIView):
    serializer_class = GoodsCategorySerializer

    queryset = GoodsCategory.objects.all()


class ShowSKUView(APIView):

    def get(self,request,pk):
        sku = SKU.objects.filter(category_id=pk)
        #
        sku_list = GoodsSKUSerializer(sku,many=True)
        #
        # print(sku_list.data)
        return Response(sku_list.data)


class ShowdetailSKUView(APIView):

    def get(self,request,id):
        sku = SKU.objects.filter(id=id)
        #
        sku_list = GoodsSKUSerializer(sku,many=True)
        #
        # print(sku_list.data)
        return Response(sku_list.data)